package com.time;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author liuxiaoding
 * @data 2019/7/14
 */
public class TimeUtil {
    /** 时间格式 */
    public static final String DATE_FORMAT_YYYY_MM_DD = "yyyy-MM-dd";

    /**
     * 取得今天日期+时间字符串.
     *
     * @return 今天日期字符串 yyyymmdd
     */
    public static String getDayTime() {
        Date date=new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_YYYY_MM_DD);
        return sdf.format(date);
    }
    /**
     * 取得今天日期+时间字符串.
     *
     * @return 今天日期字符串 yyyymmdd
     */
    public static String getDayTimeByLocalDate() {

        LocalDateTime time = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String createTime = dateTimeFormatter.format(time);
        return "xxx";
    }

    public static void main(String[] args) {
        long time=System.currentTimeMillis();
        for(int i=0;i<10000;i++){
            getDayTime();
        }
        long time1=System.currentTimeMillis();
        for(int i=0;i<10000;i++){
            getDayTimeByLocalDate();
        }
        long time2=System.currentTimeMillis();
        System.out.println("SimpleDateFormat的耗时"+(time1-time));
        System.out.println("LocalTime的耗时"+(time2-time));
    }
}
